# utils/exceptions.py
from flask import jsonify
from werkzeug.exceptions import HTTPException

class WorkflowException(Exception):
    def __init__(self, message, code=400):
        self.message = message
        self.code = code

def handle_exception(e):
    if isinstance(e, HTTPException):
        return jsonify({
            "code": e.code,
            "message": e.description
        }), e.code
    elif isinstance(e, WorkflowException):
        return jsonify({
            "code": e.code,
            "message": e.message
        }), e.code
    return jsonify({
        "code": 500,
        "message": "服务器内部错误"
    }), 500